<template>
  <div>
    <el-select
      filterable
      :value="currentValue"
      :clearable="true"
      :placeholder="placeholder"
      style="width: 100%;"
      @change="setCurrentValue"
    >
      <el-option v-for="item in options" :key="item.code" :label="item.name" :value="item.code">
        <span>{{ item.name }}</span>
        <span v-if="showDesc" style="float:right;color:#ccc">{{ item.desc }}</span>
      </el-option>
    </el-select>
  </div>
</template>
<script>
export default {
  name: 'SystemType',
  props: {
    /** 传入的值 */
    value: {
      type: String,
      default: null
    },
    showDesc: {
      type: Boolean,
      default: true
    },
    placeholder: {
      type: String,
      default: '请选择'
    },
    options: {
      type: Array || Object,
      default: () => {
        return [];
      }
    }
  },
  data() {
    return {
      types: [],
      currentValue: this.value
    };
  },
  watch: {
    value(val) {
      this.setCurrentValue(val);
    }
  },
  mounted: function() {},
  methods: {
    setCurrentValue(val) {
      this.currentValue = val;
      this.$emit('input', val);
    }
  }
};
</script>
